package com.tgr.shortLink.admin.common.web;

import com.tgr.shortLink.admin.common.interceptor.JwtTokenUserInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 描述：第二步，添加拦截器设置
 * 作者：小陶不慌张
 * 文件：AddInterceptors
 * 日期：2023/12/29 12:53
 */
@Configuration
@Slf4j
public class AddInterceptors implements WebMvcConfigurer {
    private final JwtTokenUserInterceptor jwtTokenUserInterceptor;

    public AddInterceptors(JwtTokenUserInterceptor jwtTokenUserInterceptor) {
        this.jwtTokenUserInterceptor = jwtTokenUserInterceptor;
    }


    public void addInterceptors(InterceptorRegistry registry) {
        log.info("开始注册自定义拦截器...");

        registry.addInterceptor(jwtTokenUserInterceptor)
                // 需要拦截的资源,不写的话默认全部拦截
                .addPathPatterns("/**")
                //不需要拦截的资源
                .excludePathPatterns("/api/short-link/admin/v1/user/login")
                .excludePathPatterns("/api/short-link/admin/v1/user");





    }
}
